/**
 * QueryResult.java
 */
package fss.common.communication;

import java.io.Serializable;

import fss.util.rmi.RmiId;

/**
 * A query result contains the identifier of the remote file service
 * and the file that that it contains. 
 * 
 * @author thinh
 *
 */
public class QueryResult implements Serializable {
    private static final long serialVersionUID = 1L;
    private int downloadCount = 0;
    private int uploadCount = 0;
    /**
     * The identifier of the remote file service..
     */
    private RmiId id = null;
    /**
     * The filename.
     */
    private String filename = null;
    /**
     * Total file size.
     */
    private long filesize = -1;
    /**
     * Default constructor (all values are null). Be carefule
     * using constructor.
     */
    public QueryResult() {};
    /**
     * Specific constructor.
     * @param id the id.
     * @param filename the filename.
     * @param filesize the file size.
     */
    public QueryResult(RmiId id, String filename, long filesize) {
        this.id = id;
        this.filename = filename;
        this.filesize = filesize;
    }
    /**
     * Get the identifier of the remote file service.
     * @return the identifier.
     */
    public RmiId getId() {
        return id;
    }
    /**
     * Set the identifier.
     * @param id the id.
     */
    public void setId(RmiId id) {
        this.id = id;
    }
    /**
     * Get the filename.
     * @return the filename.
     */
    public String getFilename() {
        return filename;
    }
    /**
     * Set the filename.
     * @param filename the filename.
     */
    public void setFilename(String filename) {
        this.filename = filename;
    }
    /**
     * Get the file size (in bytes).
     * @return the total bytes.
     */
    public long getFilesize() {
        return filesize;
    }
    /**
     * Set the file size.
     * @param filesize the value.
     */
    public void setFilesize(int filesize) {
        this.filesize = filesize;
    }
    public int getDownloadCount() {
        return downloadCount;
    }
    public void setDownloadCount(int downloadCount) {
        this.downloadCount = downloadCount;
    }
    public int getUploadCount() {
        return uploadCount;
    }
    public void setUploadCount(int uploadCount) {
        this.uploadCount = uploadCount;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((filename == null) ? 0 : filename.hashCode());
        result = prime * result + (int) (filesize ^ (filesize >>> 32));
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        QueryResult other = (QueryResult) obj;
        if (filename == null) {
            if (other.filename != null)
                return false;
        } else if (!filename.equals(other.filename))
            return false;
        if (filesize != other.filesize)
            return false;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }
    @Override
    public String toString() {
        StringBuilder buff = new StringBuilder();
        buff.append(id + " (" + filename + "," + filesize + " bytes) (download:" + downloadCount + ",upload:" + uploadCount + ")");
        return buff.toString();
    }
}
